local moubian = fk.CreateSkill {
  name = "lingling__moubian",
}

Fk:loadTranslationTable{
  ["lingling__moubian"] = "谋变",
  [":lingling__moubian"] = "出牌阶段，你可以弃置至少两张同名基本牌或普通锦囊牌，获得一个“每轮限一次，你可以视为使用此牌”的技能"..
  "（至多三个）。",

  ["#lingling__moubian"] = "谋变：弃置至少两张同名基本牌或普通锦囊牌，转化为每轮限一次的技能",
}

moubian:addEffect("active", {
  prompt = "#lingling__moubian",
  min_card_num = 2,
  target_num = 0,
  target_filter = Util.FalseFunc,
  can_use = function(self, player)
    return #player:getTableMark(moubian.name) < 3
  end,
  card_filter = function (self, player, to_select, selected)
    local c = Fk:getCardById(to_select)
    if c.type == Card.TypeBasic or c:isCommonTrick() then
      if #selected == 0 then
        return table.find(player:getCardIds("he"),function (cardID)
          return cardID ~= to_select and c.trueName == Fk:getCardById(cardID).trueName
        end)
      else
        return c.trueName == Fk:getCardById(selected[1]).trueName
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local name = Fk:getCardById(effect.cards[1]).name
    room:throwCard(effect.cards, moubian.name, player, player)
    if player.dead then return end
    local skillName = "lingling__moubian_"..name
    if Fk.skills[skillName] == nil then
      for i = 1, 20 do
        local s = Fk.skills["lingling__moubian_"..i]
        if s and not player:hasSkill(s, true) then
          skillName = s.name
          room:setPlayerMark(player, s.name, name)
          break
        end
      end
    end
    if Fk.skills[skillName] ~= nil then
      room:addTableMark(player, moubian.name, skillName)
      room:handleAddLoseSkills(player, skillName)
    end
  end,
})

moubian:addEffect(fk.EventLoseSkill, {
  can_refresh = function (self, event, target, player, data)
    return target == player and table.contains(player:getTableMark(moubian.name), data.skill.name)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:removeTableMark(player, moubian.name, data.skill.name)
  end,
})

return moubian
